// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

  @property(cc.Prefab)
  ballPrefab: cc.Prefab = null

  @property(cc.Node)
  ctrlAreaNode: cc.Node = null

  @property([cc.Node])
  _ballNodeArr: cc.Node[] = []

  @property
  _leave: number = 1

  // LIFE-CYCLE CALLBACKS:

  onLoad() {
    this.init()
  }

  start() {

  }

  init() {
    this._ballNodeArr = []
    this._leave = 1
    this.initMap(this._leave)
  }
  // 初始化
  initMap(leave) {

    if (leave > 4) {
      leave = 4
    }

    let ballCnt = 4 * leave

    let typeCnt: number = 1 + 1 * leave
    for (let i = 0; i < ballCnt; i++) {
      let ballNode = cc.instantiate(this.ballPrefab)
      ballNode.getComponent('ball').randBall(typeCnt)
      this.ctrlAreaNode.addChild(ballNode)
      this._ballNodeArr.push(ballNode)
    }
  }

  checkOver() {

  }
  // update (dt) {}
}
